/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.filter;

import java.util.ArrayList;
import java.util.Collection;
import ru.rakev.matcher.Matcher;

/**
 *
 * @author Rakev
 */
public class MatcherFilter<E> implements Filter<E> {

    private final Matcher<E> tester;

    public MatcherFilter(Matcher<E> tester) {
        this.tester = tester;
    }

    @Override
    public Collection<E> filter(Collection<E> source) {
        Collection<E> result = new ArrayList<>(source.size());
        for (E element : source) {
            if (tester.matches(element)) {
                result.add(element);
            }
        }
        return result;
    }
}
